package com.wwwarehouse.carddesk.fragment.functionlogincontrol;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wwwarehouse.carddesk.R;
import com.wwwarehouse.common.activity.BaseCardDeskActivity;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.custom_widget.button.StateButton;
import com.wwwarehouse.common.eventbus_event.BackListenerEvent;

import de.greenrobot.event.EventBus;


/**
 * 团队框架 ---- 暂停开启登录
 * minifly
 * 2017:11:15 9:30
 *
 * @author minfily
 */

public class FunctionLoginControlSuccessFragment extends BaseFragment implements View.OnClickListener {

    private View mRootView;
    private StateButton mGroupLoginControlSuccessContinueStatebutton;
    private StateButton mGroupLoginControlSuccessReturnStatebutton;
    private TextView successTxt;
    private String buId;
    private String name;
    private int total;
    private String type;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mRootView = inflater.inflate(R.layout.fragment_group_login_control_success, container, false);
        initView();
        return mRootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

    }


    @Override
    public void setTitle() {
        if (peekFragment() instanceof FunctionLoginControlSuccessFragment) {
            mActivity.setTitle(getString(R.string.teamdesk_login_control));
        }
    }

    @Override
    public void requestDatas() {

    }

    public void initView() {

        mGroupLoginControlSuccessContinueStatebutton = (StateButton) mRootView.findViewById(R.id.group_login_control_success_continue_statebutton);
        successTxt = (TextView) mRootView.findViewById(R.id.group_login_control_success_txt);
        mGroupLoginControlSuccessReturnStatebutton = (StateButton) mRootView.findViewById(R.id.group_login_control_success_return_statebutton);
        mGroupLoginControlSuccessReturnStatebutton.setOnClickListener(this);
        mGroupLoginControlSuccessContinueStatebutton.setOnClickListener(this);

        total = getArguments().getInt("total");
        buId = getArguments().getString("buId");
        name = getArguments().getString("name");
        // type	开启：1、暂停：0	number	@mock=1
        type = getArguments().getString("type");

        if("1".equals(type)){
            successTxt.setText("" + getString(R.string.teamdesk_login_control_stoplogin_success_open));
        }else{
            successTxt.setText("" + getString(R.string.teamdesk_login_control_stoplogin_success_stop));
        }
        EventBus.getDefault().register(this);
        ((BaseCardDeskActivity)mActivity).hideBackBt();
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        //继续设置 到第一个页面
        if (i == R.id.group_login_control_success_continue_statebutton) {
            popFragment();
        }
        //返回桌面
        else if (i == R.id.group_login_control_success_return_statebutton) {
            ((BaseCardDeskActivity)mActivity).cleanBackStack();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        ((BaseCardDeskActivity)mActivity).showBackBt();
        EventBus.getDefault().unregister(this);
    }

    public void onEventMainThread(BackListenerEvent event) {
        String message = event.getMsg();
        if (message.equals("FunctionLoginControlSuccessFragment")) {
           return;
        }
    }
}
